package com.shujia.spark

import org.apache.spark.{SparkConf, SparkContext}
import org.slf4j.{Logger, LoggerFactory}

abstract class SparkTool {

  //获取  log 打日志对象
  val logger: Logger = LoggerFactory.getLogger(this.getClass)

  var sc: SparkContext = _
  var conf: SparkConf = _

  var day_id: String = _

  def main(args: Array[String]): Unit = {

    if (args.length == 0) {

      logger.error("时间参数未指定")
      return
    }

    day_id = args(0)


    /**
      * 创建spark  运行环境
      *
      */

    conf = new SparkConf()

    //使用子类类名作为appname
    conf.setAppName(this.getClass.getSimpleName)

    //初始化spark运行环境
    this.init()

    sc = new SparkContext(conf)

    //调用子类实现的run方法
    this.run()

  }

  /**
    * 编写业务逻辑
    *
    */
  def run()

  /**
    * 初始化 设置 spark 运行参数
    *
    */
  def init()
}
